{# **
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * #}
{% use '@PrestaShop/Admin/TwigTemplateForm/bootstrap_4_layout.html.twig' %}
{% block form_start -%}
    {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-horizontal')|trim}) %}
    {{- parent() -}}
{%- endblock form_start %}

{# Labels #}

{% block form_label -%}
    {% apply spaceless %}
        {% if label is same as(false) %}
            <div class="{{ block('form_label_class') }}"></div>
        {% else %}
            {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) %}
            {{- parent() -}}
        {% endif %}
    {% endapply %}
{%- endblock form_label %}

{% block form_label_class -%}
  form-control-label
{%- endblock form_label_class %}

{# Rows #}

{% block form_row -%}
    {% apply spaceless %}
        <div class="{{ block('form_row_class') }} {% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
            {{ form_label(form) }}
            <div class="{{ block('form_group_class') }}">
                {{ form_widget(form) }}
                {{ form_errors(form) }}
                {{ block('form_help') }}
            </div>
        </div>
    {% endapply %}
{%- endblock form_row %}

{% block checkbox_row -%}
    {{- block('checkbox_radio_row') -}}
{%- endblock checkbox_row %}

{% block radio_row -%}
    {{- block('checkbox_radio_row') -}}
{%- endblock radio_row %}

{% block checkbox_radio_row -%}
    {% apply spaceless %}
        <div class="form-group{% if not valid %} has-error{% endif %}">
            <div class="{{ block('form_label_class') }}"></div>
            <div class="{{ block('form_group_class') }}">
                {{ form_widget(form) }}
                {{ form_errors(form) }}
            </div>
        </div>
    {% endapply %}
{%- endblock checkbox_radio_row %}

{% block submit_row -%}
    {% apply spaceless %}
        <div class="form-group">
            <div class="{{ block('form_label_class') }}"></div>
            <div class="{{ block('form_group_class') }}">
                {{ form_widget(form) }}
            </div>
        </div>
    {% endapply %}
{% endblock submit_row %}

{% block form_group_class -%}
    col-sm
{%- endblock form_group_class %}

{% block form_row_class -%}
    form-group row
{%- endblock form_row_class %}

{% block ip_address_text_widget %}
<div class="input-group">
    {{- block('form_widget_simple') -}}
    <button type="button" class="btn btn-outline-primary add_ip_button" data-ip="{{ currentIp }}">
        <i class="material-icons">add_circle</i> {{ 'Add my IP'|trans({}, 'Admin.Actions') }}
    </button>
</div>
{% endblock ip_address_text_widget %}

{% block switch_widget %}
<div class="input-group">
    {{- parent() -}}
</div>
{% endblock switch_widget %}

{% block text_with_length_counter_widget %}
  <div class="input-group js-text-with-length-counter">
    {% set current_length = form.vars.max_length - form.vars.value|length %}

    {% if form.vars.position == 'before' %}
      <div class="input-group-prepend">
        <span class="input-group-text js-countable-text">{{ current_length }}</span>
      </div>
    {% endif %}

    {% set attr = attr|merge(input_attr) -%}
    {% set attr = attr|merge({'data-max-length': form.vars.max_length, maxlength: form.vars.max_length, class: (attr.class|default('') ~ ' js-countable-input')|trim}) -%}

    {% if form.vars.input == 'textarea' %}
      {{- block('textarea_widget') -}}
    {% else %}
      {{- block('form_widget_simple') -}}
    {% endif %}

    {% if form.vars.position == 'after' %}
      <div class="input-group-append">
        <span class="input-group-text js-countable-text">{{ current_length }}</span>
      </div>
    {% endif %}
  </div>
{% endblock text_with_length_counter_widget %}

{%- block number_widget -%}
  {%- set type = type|default('text') -%}
  <div class="input-group">
    {{- block('form_unit_prepend') -}}
    <div class="w-100">{{- block('form_widget_simple') -}}</div>
    {{- block('form_unit') -}}
  </div>
{%- endblock number_widget -%}

{%- block integer_widget -%}
  {%- set type = type|default('number') -%}
  <div class="input-group">
    {{- block('form_unit_prepend') -}}
    {{- block('form_widget_simple') -}}
    {{- block('form_unit') -}}
  </div>
{%- endblock integer_widget -%}

{% block form_unit %}
  {% if form.vars.unit is defined and not form.vars.prepend_unit %}
    <div class="input-group-append">
      <span class="input-group-text">{{ form.vars.unit }}</span>
    </div>
  {% endif %}
{% endblock form_unit %}

{% block form_unit_prepend %}
  {% if form.vars.unit is defined and form.vars.prepend_unit %}
    <div class="input-group-prepend">
      <span class="input-group-text">{{ form.vars.unit }}</span>
    </div>
  {% endif %}
{% endblock form_unit_prepend %}

{% block amount_currency_widget %}
  <div class="input-group">
    <input id="{{ form.amount.vars.id }}" type="text" class="form-control" name="{{ form.amount.vars.full_name }}" required>
    <div class="input-group-append">
      {% if form.amount.vars.unit is defined %}
        <span class="input-group-text">{{ form.amount.vars.unit }}</span>
        {{ form_widget(form.id_currency) }}
      {% else %}
        {{ form_widget(form.id_currency, {attr: {class: 'form-control'}}) }}
      {% endif %}
    </div>
  </div>
{% endblock %}
